package com.newgoldcurrency.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.newgoldcurrency.bean.MinerBean;
import com.newgoldcurrency.databinding.ItemMinerBinding;

import java.util.List;

public class MinerAdapter extends ArrayAdapter<MinerBean> {
    private final Activity context;
    public MinerAdapter(@NonNull Activity context, @NonNull List<MinerBean> objects) {
        super(context, 0, objects);
        this.context=context;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        @SuppressLint("ViewHolder") @NonNull ItemMinerBinding binding = ItemMinerBinding.inflate(context.getLayoutInflater());
        MinerBean bean = getItem(position);
        binding.itemMinerCode.setText(bean.invitation_code);
        if (bean.message_count.equals("0")){
            binding.itemMinerMsg.setVisibility(View.INVISIBLE);
        }else{
            binding.itemMinerMsg.setVisibility(View.VISIBLE);
            if (Integer.parseInt(bean.message_count)>99){
                binding.itemMinerMsg.setText("99+");
            }else {
                if (Integer.parseInt(bean.message_count)<10){
                    binding.itemMinerMsg.setText(bean.message_count);
                }else {
                    binding.itemMinerMsg.setText(bean.message_count);
                }
            }
        }




        return binding.getRoot();
    }
}
